|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Fast Track Visual C++ 6.0 Programming
Listing 6.2 Redraw.h
class CRedraw
{
protected:
CMetaFileDC* pDC;
public:
CRedraw(){pDC = new CMetaFileDC();
pDC->Create();}
~CRedraw(){delete pDC;}
CMetaFileDC* GetDC() {return pDC;}
void PlayMetaFile(CDC* pRefreshDC){
HMETAFILE OldMetaFileHandle = pDC->Close();
if(OldMetaFileHandle == NULL)
return;
pRefreshDC->PlayMetaFile(OldMetaFileHandle);
CMetaFileDC* ReplacementMetaFile = new CMetaFileDC();
ReplacementMetaFile->Create();
ReplacementMetaFile->PlayMetaFile(OldMetaFileHandle);
DeleteMetaFile(OldMetaFileHandle);
delete pDC;
pDC = ReplacementMetaFile;}
};
Listing 6.3 CirclesView.h and CirclesView.cpp
// CirclesView.h : interface of the CCirclesView class
//
/////////////////////////////////////////////////////////////////////////////
#if
!defined(AFX_CIRCLESVIEW_H__9036416F_A23B_11D1_887F_
D42B07C10710__INCLUDED_)
#define AFX_CIRCLESVIEW_H__9036416F_A23B_11D1_887F_
D42B07C10710__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Redraw.h"
class CCirclesView : public CView
{
protected: // create from serialization only
CCirclesView();
DECLARE_DYNCREATE(CCirclesView)
CPoint point1, point2;
CRedraw redraw;
// Attributes
public:
CCirclesDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCirclesView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CCirclesView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CCirclesView)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in CirclesView.cpp
inline CCirclesDoc* CCirclesView::GetDocument()
{ return (CCirclesDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional
declarations immediately before the previous line.
#endif // !defined(AFX_CIRCLESVIEW_H__9036416F_A23B_11D1_887F_
D
42B07C10710__INCLUDED_)
// CirclesView.cpp : implementation of the CCirclesView class
//
#include "stdafx.h"
#include "Circles.h"
#include "CirclesDoc.h"
#include "CirclesView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCirclesView
IMPLEMENT_DYNCREATE(CCirclesView, CView)
BEGIN_MESSAGE_MAP(CCirclesView, CView)
//{{AFX_MSG_MAP(CCirclesView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCirclesView construction/destruction
CCirclesView::CCirclesView()
{
// TODO: add construction code here
point1.x = -1;
point1.y = -1;
}
CCirclesView::~CCirclesView()
{
}
BOOL CCirclesView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCirclesView drawing
void CCirclesView::OnDraw(CDC* pDC)
{
CCirclesDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
redraw.PlayMetaFile(pDC);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCirclesView printing
BOOL CCirclesView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCirclesView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCirclesView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCirclesView diagnostics
#ifdef _DEBUG
void CCirclesView::AssertValid() const
{
CView::AssertValid();
}
void CCirclesView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCirclesDoc* CCirclesView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCirclesDoc)));
return (CCirclesDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCirclesView message handlers
void CCirclesView::OnLButtonDown(UINT nFlags, CPoint point)
{
point1 = point;
CView::OnLButtonDown(nFlags, point);
}
void CCirclesView::OnLButtonUp(UINT nFlags, CPoint point)
{
point2 = point;
CClientDC* pDC;
pDC = new CClientDC(this);
pDC->Ellipse(point1.x, point1.y, point2.x, point2.y);
redraw.GetDC()->Ellipse(point1.x, point1.y, point2.x, point2.y);
CView::OnLButtonUp(nFlags, point);
}
Whats AheadIn the next chapter, we work with the ins and outs of 32-bit memory handling, including scanning memory to see whats there, allocating and deallocating memory, and communicating between processes using shared memory. This is a popular programming topic, so lets start our exploration
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |